#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>

int main()
{
  pid_t fd = fork();
  if(fd < 0){
    perror("fork");
    return 1;
  }

  if(fd == 0){
    printf("I am child!\n");
    sleep(3);
    int *p = NULL;
    *p = 100;
   int a = 1/ 0;
    return 1;
  }

  int status = 0;
  pid_t wfd =  waitpid(fd, &status, 0);
  if(wfd < 0){
    perror("waitpid");
    return 2;
  }
  if(__WIFSIGNALED(status)){
    printf("killed by %d signal!\n", WTERMSIG(status));
    printf("core dump:%d\n", (status >> 7) & 1);
  }
  return 0;
}

